print("冒泡排序"
      "每外层循环一次，内层就两两比较")
def maopao(nums:list[int])->list[int]:
    for i in range(0,len(nums)):
        for j in range(0,len(nums)-i-1):
            if nums[j]<nums[j+1]:
                nums[j],nums[j+1]=nums[j+1],nums[j]
    print(nums)
    return nums

print("插入排序"
      "每次选择一个元素和其前面的所有元素比较")
def charupaixu(nums:list[int])->list[int]:
    for i in range(0,len(nums)):
        current_index=i
        while current_index>0:
            if nums[current_index]>nums[current_index-1]:
                nums[current_index],nums[current_index-1]=nums[current_index-1],nums[current_index]
            current_index=current_index-1
    print(nums)
    return nums

print("选择排序"
      "双指针：当前指针和最小元素索引指针，当前指针和最小元素索引指针开始指向相同位置"
      "然后依次往后遍历找到最小的元素的索引，然后最小元素的索引和当前索引对应的元素交换"
      "然后变更当前索引")
def xuanzepaixu(nums:list[int])->list[int]:
    current_index=0
    for i in range(0,len(nums)):
        max_index=current_index
        for j in range(current_index,len(nums)):
            if nums[j]>nums[max_index]:
                max_index=j
        nums[i],nums[max_index]=nums[max_index],nums[i]
        current_index=current_index+1
    print(nums)
    return nums

def method001(nums):
    for i in range(0,len(nums)):
        for j in range(0,len(nums)-1-i):
            if nums[j]<nums[j+1]:
                nums[j],nums[j+1]=nums[j+1],nums[j]
    print(nums)

def method002(nums):
    for i in range(0,len(nums)):
        current_index=i
        while current_index >0:
            if nums[current_index]>nums[current_index-1]:
                nums[current_index],nums[current_index-1]=nums[current_index-1],nums[current_index]
            current_index=current_index-1
    print(nums)

def method003(nums):
    # current_index=0
    for i in range(0,len(nums)):
        current_index=i
        min_index=current_index
        for j in range(current_index,len(nums)):
            if nums[j]>nums[min_index]:
                min_index=j
        nums[current_index],nums[min_index]=nums[min_index],nums[current_index]
    print(nums)

def method004(nums):
    for i in range(0,len(nums)):
        max_index=i
        for j in range(i,len(nums)):
            if nums[max_index]<nums[j]:
                max_index=j
        if max_index!=i:
            nums[i],nums[max_index]=nums[max_index],nums[i]
    print(nums)


if __name__ == '__main__':
    source_list = [1, 2, 4, 5, 7, 23, 3, 1, 2, 5, 3]
    # maopao(source_list)
    # charupaixu(source_list)
    # xuanzepaixu(source_list)
    # method001(source_list)
    # method002(source_list)
    # method003(source_list)
    method004(source_list)
